package com.lanou.dllo.findfood.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.lanou.dllo.findfood.R;

/**
 * Created by dllo on 15/10/28.
 */
public class BookFragment extends Fragment {
    private WebView bookMessageWeb;
    private String mages;
    private String title;
    private TextView booktitle,PageId,sumPage;
    private int id,sum;
    private ProgressBar progressBar;


    private static BookFragment bookFragment;
    private BookFragment(){

    }

    public static  BookFragment getInstance(String mages,String title,int id,int sum){
        BookFragment fragment = new BookFragment();
        Bundle args = new Bundle();
        args.putString("mages",mages);
        args.putString("title",title);
        args.putInt("id",id);
        args.putInt("sum",sum);

        fragment.setArguments(args);
        return  fragment;
    }

    //初始化的方法
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    //得到参数
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null){
            mages = bundle.getString("mages");
            title = bundle.getString("title");
            id = bundle.getInt("id");
            sum = bundle.getInt("sum");

        }

    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

      View v= inflater.inflate(R.layout.recyler_book_item,null);
        bookMessageWeb = (WebView) v.findViewById(R.id.bookMessage);
        progressBar = (ProgressBar) v.findViewById(R.id.progressBar);

        progressBar.setVisibility(android.view.View.VISIBLE);

        booktitle = (TextView) v.findViewById(R.id.booktitle);
        PageId = (TextView) v.findViewById(R.id.PageId);
        PageId.setText(id + "");

        sumPage = (TextView) v.findViewById(R.id.sumPage);
        sumPage.setText(sum + "");


        booktitle.setText(title);
        String htmlString= mages;
        final String mimrTypeString = "text/html";
        final String encoding = "utf-8";
        bookMessageWeb.loadDataWithBaseURL("fake://not/needed", htmlString, mimrTypeString, encoding, "");
    //   bookMessageWeb.setInitialScale(140);//设置内容显示比例大小
        // 设置可以支持缩放
        bookMessageWeb.getSettings().setSupportZoom(true);
        //自适应屏幕 两句话
        bookMessageWeb.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        bookMessageWeb.getSettings().setLoadWithOverviewMode(true);
        return v;
    }




}
